import java.io.*;
import java.net.*;
public class Client {

    public static void main(String[] args) {
        Socket socket = null;
        InputStream is = null;
        OutputStream os = null;
        //服务器端IP地址
        String serverIP = "192.168.56.1";
        //服务器端端口号
        int port = 8089;
        //发送内容
        System.out.println("输入中缀表达式：(1+2)*3/4");
        String output;
        MyBC theTrans = new MyBC("(1+2)*3/4");
        output = theTrans.doTrans();
        try {
            //建立连接
            socket = new Socket(serverIP, port);
            System.out.println("建立连接成功！");
            //发送数据
            os = socket.getOutputStream();
            os.write(output.getBytes());
            System.out.println("发送数据成功！");
            //接收数据
            is = socket.getInputStream();
            byte[] b = new byte[1024];
            int n = is.read(b);
            System.out.println("接收数据成功！");
            //输出反馈数据
            System.out.println("来自服务器的数据内容为：" + new String(b, 0, n));
        } catch (Exception e) {
            e.printStackTrace(); //打印异常信息
        } finally {
            try {
                //关闭流和连接
                is.close();
                os.close();
                socket.close();
            } catch (Exception e2) {
            }
        }
    }
}